/**
 * 
 */
package com.ffcs.crmd.tsp.admin.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.ffcs.crmd.tsp.admin.service.ITspClientService;
import com.ffcs.crmd.tsp.api.dto.client.TspResult;
import com.ffcs.crmd.tsp.client.core.TspClient;
import com.ffcs.crmd.tsp.common.client.enu.TspResultType;
import com.ffcs.crmd.tsp.common.exception.TspException;

/**
 * 功能说明:
 *
 * @author FFCS-ZHONGFUHUA
 * 
 * @since 
 *
 */
public abstract class AbstractService {
    
    @Autowired
    protected ITspClientService  tspClientService;
    
    protected TspClient getClient(String clusterName) throws TspException{
        TspClient tspClient = tspClientService.getClient(clusterName);
        if(tspClient == null){
            tspClient = tspClientService.getAllClient().get(0);
            if(tspClient == null){
                throw new TspException("当前环境没有集群，请添加集群");
            }
        }
        return tspClient;
    }
    
    
    protected void validateResult(TspResult<?> tspResult) throws TspException{
        if (tspResult.getTspResultType() == TspResultType.FAIL) {
            throw new TspException(tspResult.getErrorMessage());
        }
    }
}
